﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:r="clr-namespace:ChristianMoser.WpfInspector.Services.Resources" xmlns:c="clr-namespace:ChristianMoser.WpfInspector.UserInterface.Converters" xmlns:UserInterface="clr-namespace:ChristianMoser.WpfInspector.UserInterface">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/Inspector;component/UserInterface/VisualResources/Brushes.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <Style TargetType="ListBox">
        <Style.Resources>
            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#73706a" />
            <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
        </Style.Resources>
        <Setter Property="Background" Value="{DynamicResource DefaultBackgroundBrush}" />
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="BorderBrush" Value="{DynamicResource DefaultBorderBrush}" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ListBox}">
                    <Border x:Name="Bd" SnapsToDevicePixels="true" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="1">
                        <ScrollViewer Padding="{TemplateBinding Padding}" Focusable="false" VerticalScrollBarVisibility="Auto">
                            <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                        </ScrollViewer>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
                        </Trigger>
                        <Trigger Property="IsGrouping" Value="true">
                            <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="TreeListToggleStyle" TargetType="ToggleButton">
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ToggleButton">
                    <Border Background="Transparent">
                        <Path x:Name="ExpandPath" VerticalAlignment="Center" Margin="1,1,1,1" Fill="{DynamicResource DefaultForegroundBrush}" Data="M 4 0 L 8 4 L 4 8 Z"/>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsChecked" Value="True">
                            <Setter Property="Data" TargetName="ExpandPath" Value="M 0 4 L 8 4 L 4 8 Z"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="TreeListBoxItemStyle" TargetType="ListBoxItem">
        <Setter Property="UserInterface:ListBoxItemHelper.ExpandOnClick" Value="True" />
    </Style>

    <Style x:Key="TreeListBoxStyle" TargetType="ListBox">
        <Style.Resources>
            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
            <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
        </Style.Resources>
        <Setter Property="BorderThickness" Value="0"  />
        <Setter Property="UserInterface:ListBoxItemHelper.BringIntoView" Value="True" />
        <Setter Property="VirtualizingStackPanel.VirtualizationMode" Value="Recycling"  />
        <Setter Property="Background" Value="Transparent"  />
        <Setter Property="HorizontalContentAlignment" Value="Left"  />
        <Setter Property="ItemContainerStyle"  Value="{StaticResource TreeListBoxItemStyle}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListBox">
                    <ScrollViewer Margin="0" Focusable="false" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
                        <VirtualizingStackPanel IsItemsHost="True" CanHorizontallyScroll="True" CanVerticallyScroll="True"/>
                    </ScrollViewer>
                </ControlTemplate>
            </Setter.Value>
        </Setter>

        <Setter Property="ItemTemplate">
            <Setter.Value>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" Background="Transparent" Margin="{Binding Level, Converter={c:LevelToMarginConverter}}" HorizontalAlignment="Left">
                        <ToggleButton x:Name="tb" ClickMode="Press" IsChecked="{Binding Path=IsExpanded}" Style="{StaticResource TreeListToggleStyle}" />
                        <Border x:Name="selection" Background="Transparent" BorderThickness="1" CornerRadius="3" >
                            <StackPanel Orientation="Horizontal" Margin="2,0">
                                <Image x:Name="icon" IsHitTestVisible="False" Source="/Inspector;component/Images/window.png" Margin="2,0" Stretch="None" />
                                <TextBlock x:Name="name" Foreground="{DynamicResource DefaultForegroundBrush}" IsHitTestVisible="False" Text="{Binding Path=Name}" VerticalAlignment="Center" />
                                <TextBlock Foreground="#bbbbbb" Margin="8,0,0,0" IsHitTestVisible="False" Text="{Binding Path=ElementCount, StringFormat='{}({0})'}" VerticalAlignment="Center" />
                            </StackPanel>
                        </Border>
                        <StackPanel.ToolTip>
                            <ToolTip Width="200" Height="200" >
                                <Grid>
                                    <Grid.Background>
                                        <DrawingBrush ViewboxUnits="Absolute" ViewportUnits="Absolute" Viewbox="0,0,32,32" Viewport="0,0,32,32" TileMode="Tile" >
                                            <DrawingBrush.Drawing>
                                                <DrawingGroup>
                                                    <GeometryDrawing Geometry="M0 0 L 16 0 L 16 16 L 0 16 z" Brush="#eeeeee" />
                                                    <GeometryDrawing Geometry="M16 16 L 32 16 L 32 32 L 16 32 z" Brush="#eeeeee" />
                                                </DrawingGroup>
                                            </DrawingBrush.Drawing>
                                        </DrawingBrush>
                                    </Grid.Background>
                                    <Rectangle>
                                        <Rectangle.Fill>
                                            <VisualBrush Visual="{Binding Instance}"  Stretch="Uniform" />
                                        </Rectangle.Fill>
                                    </Rectangle>
                                </Grid>
                            </ToolTip>
                        </StackPanel.ToolTip>
                    </StackPanel>
                    <DataTemplate.Triggers>
                        <DataTrigger Binding="{Binding Children.Count}" Value="0">
                            <Setter Property="Visibility" TargetName="tb" Value="Hidden"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}}" Value="True">
                            <Setter Property="Background" TargetName="selection" Value="{DynamicResource SelectionBackgroundBrush}"/>
                            <Setter Property="BorderBrush" TargetName="selection" Value="{DynamicResource SelectionBorderBrush}"/>
                            <Setter Property="BorderThickness" TargetName="selection" Value="1"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Type}" Value="Window">
                            <Setter TargetName="icon" Property="Source" Value="/Inspector;component/Images/window.png"  />
                            <Setter TargetName="name" Property="FontWeight" Value="Bold" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Type}" Value="UserControl">
                            <Setter TargetName="name" Property="FontWeight" Value="Bold" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Type}" Value="TextBlock">
                            <Setter TargetName="icon" Property="Source" Value="/Inspector;component/Images/textblock.png"  />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Type}" Value="StackPanel">
                            <Setter TargetName="icon" Property="Source" Value="/Inspector;component/Images/stackpanel.png"  />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Type}" Value="Grid">
                            <Setter TargetName="icon" Property="Source" Value="/Inspector;component/Images/grid.png"  />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Type}" Value="Button">
                            <Setter TargetName="icon" Property="Source" Value="/Inspector;component/Images/button.png"  />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Type}" Value="TextBox">
                            <Setter TargetName="icon" Property="Source" Value="/Inspector;component/Images/textbox.png"  />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Type}" Value="TabControl">
                            <Setter TargetName="icon" Property="Source" Value="/Inspector;component/Images/tabcontrol.png"  />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Type}" Value="Image">
                            <Setter TargetName="icon" Property="Source" Value="/Inspector;component/Images/image.png"  />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Type}" Value="ComboBox">
                            <Setter TargetName="icon" Property="Source" Value="/Inspector;component/Images/combobox.png"  />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Type}" Value="ListBox">
                            <Setter TargetName="icon" Property="Source" Value="/Inspector;component/Images/listbox.png"  />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Type}" Value="CheckBox">
                            <Setter TargetName="icon" Property="Source" Value="/Inspector;component/Images/checkbox.png"  />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Type}" Value="DockPanel">
                            <Setter TargetName="icon" Property="Source" Value="/Inspector;component/Images/dockpanel.png"  />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Type}" Value="ContentControl">
                            <Setter TargetName="icon" Property="Source" Value="/Inspector;component/Images/contentcontrol.png"  />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Type}" Value="Canvas">
                            <Setter TargetName="icon" Property="Source" Value="/Inspector;component/Images/canvas.png"  />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Type}" Value="RadioButton">
                            <Setter TargetName="icon" Property="Source" Value="/Inspector;component/Images/radiobutton.png"  />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Type}" Value="Border">
                            <Setter TargetName="icon" Property="Source" Value="/Inspector;component/Images/border.png"  />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Type}" Value="Expander">
                            <Setter TargetName="icon" Property="Source" Value="/Inspector;component/Images/expander.png"  />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Type}" Value="GridSplitter">
                            <Setter TargetName="icon" Property="Source" Value="/Inspector;component/Images/gridsplitter.png"  />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Type}" Value="Menu">
                            <Setter TargetName="icon" Property="Source" Value="/Inspector;component/Images/menu.png"  />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Type}" Value="MediaElement">
                            <Setter TargetName="icon" Property="Source" Value="/Inspector;component/Images/mediaelement.png"  />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Type}" Value="ListView">
                            <Setter TargetName="icon" Property="Source" Value="/Inspector;component/Images/listview.png"  />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Type}" Value="Slider">
                            <Setter TargetName="icon" Property="Source" Value="/Inspector;component/Images/slider.png"  />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Type}" Value="Separator">
                            <Setter TargetName="icon" Property="Source" Value="/Inspector;component/Images/separator.png"  />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Type}" Value="ScrollViewer">
                            <Setter TargetName="icon" Property="Source" Value="/Inspector;component/Images/scrollviewer.png"  />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Type}" Value="RichTextBox">
                            <Setter TargetName="icon" Property="Source" Value="/Inspector;component/Images/richtextbox.png"  />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Type}" Value="ProgressBar">
                            <Setter TargetName="icon" Property="Source" Value="/Inspector;component/Images/progressbar.png"  />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Type}" Value="PasswordBox">
                            <Setter TargetName="icon" Property="Source" Value="/Inspector;component/Images/passwordbox.png"  />
                        </DataTrigger>
                    </DataTemplate.Triggers>
                </DataTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="SelectorListBoxStyle" TargetType="ListBox">
        <Style.Resources>
            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#e4e4e4" />
            <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
        </Style.Resources>
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListBox">
                    <Border BorderThickness="0,1" Background="{DynamicResource DefaultBackgroundBrush}" BorderBrush="{DynamicResource DefaultBorderBrush}" >
                        <ItemsPresenter Margin="16"  />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="ItemTemplate">
            <Setter.Value>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <Image Height="24" Width="24" Stretch="Uniform" Source="{Binding ProcessIcon}"  />
                        <TextBlock VerticalAlignment="Center" Foreground="{DynamicResource DefaultForegroundBrush}" Margin="8,8,4,8" Text="{Binding Name}"  />
                        <TextBlock VerticalAlignment="Center" Foreground="{DynamicResource DefaultForegroundBrush}" Text="{Binding ProcessId, StringFormat='{}({0})'}" Opacity="0.5" />
                    </StackPanel>
                </DataTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>